package com.baosight.demo.ice;

import com.baosight.Xemo.HelloPrx;
import com.baosight.demo.service.ServiceDemo;
//import com.baosight.hdsdk.HDTagManager;
import com.baosight.ice.annotation.IceMark;
import com.baosight.ice.util.PrxHelper;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.xcyber.CallInfo;
import com.baosight.xcyber.Demo;
import com.baosight.xcyber.DemoPrx;
import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.Current;
import com.zeroc.Ice.ObjectPrx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import xCyber.TreeManager;
import xCyber.TreeManagerPrx;

import java.util.HashMap;
import java.util.Map;

@IceMark(identity = "xCyber/Demo")
public class DemoImpI implements Demo {
//    @Autowired
//    private HDTagManager tagManager;

    public static Logger logger= LoggerFactory.getLogger(DemoImpI.class);
    public static int count=0;
    public int index;
    @Autowired
    ServiceDemo se;
    @Value("${testV1}")
    private String testV1;

    @Autowired
    public Communicator communicator;

    public DemoImpI(){
        count++;
        index=count;
        logger.info("new DemoImpI index {},autoWired is {},testV1 is {}",count,se==null,testV1==null?"null":testV1);

    }
    /**
     * 测试方法简易
     * @param current dsavxczvxc
     *                dsaffsaf
     *                safsaf
     *                sdfadf
     *                dsafasf
     * @return 仙草蜜
     *  dsfadfsaf
     *  dsfafsff
     *  sf
     */
    @Override
    public int callEasy(Current current) {
        logger.info("index {} receiceMsg",index);
        try {
            logger.info("{}  aaaa",communicator==null);
//            ObjectPrx xCyberj = communicator.stringToProxy("xCyber/Demo");
//            DemoPrx helloPrx = DemoPrx.checkedCast(xCyberj);
//            logger.info("{}",helloPrx.callMiddle(12));
            String identity="xCyber/TreeManager";
            ObjectPrx commonPrx = communicator.stringToProxy(identity);
            TreeManagerPrx prx= TreeManagerPrx.checkedCast(commonPrx);
            System.out.println(prx.GetTopNodes());
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.info("index {} end",index);

        return -123456;
    }

    /**
     * 测试方法难xnvkzlnf
     * afnsd9fj232l;nmf90msa
     * smnvosa0o91r
     * @param num 数字ADASshafksn\
     *            safjkslajlkfnsla
     *            z1'2\;3\129o4210s;a\
     *            nclkxmz
     * @param callInfo 特殊结果BFfsa clkxznvojeaomslkfmnal;s
     *                 falknsvk;ahsoknrwnfoianjlks\
     *                 nfksolajvioxzmpqnep21keh0389uksandufva0
     *
     * @param current qwejlksajfosaujf
     *                dsajoivcnxl;neioarfh
     *                salkvnx,mzjoiwurow
     *
     * @return 娃哈哈xkjzbhi8u9021321
     * sauf9203i41[km41
     * f9021j3e41k2ej1
     */
    @Override
    public CallInfo callHard(int num, CallInfo callInfo, Current current) {
        callInfo.status+=num;
        logger.info("hard call");
        return callInfo;
    }

    /**
     * 测试方法中等
     * @param num 数字BBSSAAsafsf
     *            asdfsaf
     *            adsfsfsa
     *
     * @param current vxczvrwafa
     *                vsazweqwr
     * @return 谷粒谷粒
     */
    @Override
    public float callMiddle(int num, Current current) {
        DemoPrx servicePrxCache = PrxHelper.getServicePrxCache(DemoPrx.class, "xCyber/Demo");
        servicePrxCache.callHard(num,new CallInfo(){{
            status=999;
        }});
        System.out.println("孙霖发黄了");
        return num+1.2345f;
    }

    @Override
    public CallInfo callString(String a, Map<String,String> __blocks__, Current current) {
        System.out.println(a);
        System.out.println(__blocks__);
        CallInfo callInfo=new CallInfo();
        callInfo.msg="dsafd";
        callInfo.kv=new HashMap<String, String>(){{
            put("a","b");
            put("c","d");
        }};
        callInfo.params=new String[]{"1","a","2","b"};
        return callInfo;
    }

    public String testMethod(int num_1,String str_straa_1){
        logger.info("num_1 :{} ,str_straa_1:{}",num_1,str_straa_1);
        throw new RuntimeException("嘻嘻哈哈");
        //return str_straa_1+num_1;
    }

    public EiInfo callEiInfo(EiInfo eiInfo){
        eiInfo.set("fdaf","fdasfa");
        EiBlockMeta eiMetadata=new EiBlockMeta();
        EiColumn eiColumn = new EiColumn("product_id");
        eiColumn.setDescName("产品代号");
        eiColumn.setMaxLength(20);
//		eiColumn.setNotNull( true );
        eiColumn.setNullable(false);
        eiColumn.setPrimaryKey(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("company_name");
        eiColumn.setDescName("公司名称");
        eiColumn.setMaxLength(20);
//		eiColumn.setNotNull( false );
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("made_country");
        eiColumn.setDescName("产地");
        eiColumn.setMaxLength(20);
//		eiColumn.setNotNull( false );
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("sale_date");
        eiColumn.setDescName("上市日期");
        eiColumn.setMaxLength(20);
//		eiColumn.setNotNull( false );
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("price");
        eiColumn.setDescName("价格");
        eiColumn.setType("N");
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("company_page");
        eiColumn.setDescName("公司首页");
        eiColumn.setMaxLength(255);
        eiColumn.setWidth(150);
//		eiColumn.setNotNull( false );
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);

        eiColumn = new EiColumn("search");
        eiColumn.setDescName("Google查询");
        eiColumn.setMaxLength(20);
//		eiColumn.setNotNull( false );
        eiColumn.setNullable(true);
        eiMetadata.addMeta(eiColumn);


        EiBlock eiBlock=new EiBlock("a");
        eiBlock.addBlockMeta(eiMetadata);
        eiBlock.addRow(new HashMap<String,String>(){{
            put("product_id","1");
            put("company_name","2");
            put("made_country","3");
            put("sale_date","4");
            put("price","5");
            put("search","6");
        }});
        eiInfo.addBlock(eiBlock);
        return eiInfo;
    }
}
